package com.chess.chessplay.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chess.chessplay.mapper.PlayerMapper;
import com.chess.chessplay.pojo.Player;
import com.chess.chessplay.service.PlayerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PlayerServiceImpl extends ServiceImpl<PlayerMapper, Player> implements PlayerService {
    @Autowired
    private PlayerMapper playerMapper;

    @Override
    public Player findPlayerById(Integer id) {
        return playerMapper.selectById(id);
    }

    @Override
    public Player findPlayerByUsername(String username) {
        QueryWrapper<Player> wrapper = new QueryWrapper();
        wrapper.eq("username",username);

        return playerMapper.selectOne(wrapper);
    }

    @Override
    public void InsertPlayer(Player player) {
        baseMapper.insert(player);
    }

    @Override
    public void updatePlayerById(Player player) {
        baseMapper.updateById(player);
    }
}
